//
//  UIBarButtonItem + Extension.swift
//  SinaWeiBo
//
//  Created by Leon 笑 竹 on 2017/8/1.
//  Copyright © 2017年 Leon 笑 竹. All rights reserved.
//

import Foundation


extension UIBarButtonItem {
    
    
    /// 添加便利导航按钮
    ///
    /// - Parameters:
    ///   - title: 名称
    ///   - fontSize: 字体大小
    ///   - target: 目标
    ///   - isBack : 如果bool为true则有返回按钮，加上图标
    ///   - action: 行为
    
    convenience init(title : String , fontSize : CGFloat = 16 , target : AnyObject?, action : Selector, isBack : Bool){
     
        let btn : UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        //添加返回的按钮
        if isBack {
            //普通状态
            btn.setImage(UIImage.init(named: "navigationbar_back_withtext")?.withRenderingMode(.alwaysOriginal), for: .normal)
            //高亮状态
            btn.setImage(UIImage.init(named: "navigationbar_back_withtext_highlighted")?.withRenderingMode(.alwaysOriginal), for: .highlighted)
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        //适应宽度
        btn.sizeToFit()
        self.init(customView:btn)
    }
}
